/*******************************
* IV_do_ivregs.do     *
********************/

#delimit;
xtset sch_id;

eststo clear;
eststo: xtivreg2 Y $spec3 (T1 T2 = $instrument_avg) if numberstudents_e>=5 & numberstudents_m>=5, fe cluster(sch_id);
estadd scalar nst = round(e(N),10); estadd scalar firstf = e(cdf); estadd scalar ovid = e(jp);
eststo: xtivreg2 Y $spec3 (T1 T2 =  $instrument3 $instrument4 $instrument5), fe cluster(sch_id);
estadd scalar nst = round(e(N),10); estadd scalar firstf = e(cdf); estadd scalar ovid = e(jp);
eststo: xtivreg2 Y $spec3 (T1 T2 =  $instrument_avg $instrument3 $instrument4 $instrument5)  if numberstudents_e>=3 & numberstudents_m>=3, fe cluster(sch_id);
estadd scalar nst = round(e(N),10); estadd scalar firstf = e(cdf); estadd scalar ovid = e(jp);
esttab using $tables\EdEx_rep.tex, append cells(b(fmt(2) star) se(fmt(2) par))
collabels(none) 
nomtitles mgroups("Bartik" "Transitory" "Both", pattern(1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span) 
 starlevels(* 0.10 ** 0.05 *** 0.01) label keep(T1 T2) 
stats(r2 r2_a nst firstf ovid, fmt(2 2 0 2 2) labels(" $ R^2$ " "Adjusted $ R^2$ " "N" "1st StageF-test" "Over-identification test")) title(2SLS: The Effect of Teacher Expectation, with School FE);

eststo clear;
eststo: ivreg2hdfe  if numberstudents_e>=5 & numberstudents_m>=5,  depvar(Y) ex($spec3) en(T1 T2) iv($instrument_avg) id1(tidm) id2(tide) cluster(sch_id);
estadd scalar nst = round(e(N),10); estadd scalar firstf = e(cdf); estadd scalar ovid = e(jp);
eststo: ivreg2hdfe ,  depvar(Y) ex($spec3) en(T1 T2) iv($instrument3 $instrument4 $instrument5) id1(tidm) id2(tide) cluster(sch_id);
estadd scalar nst = round(e(N),10); estadd scalar firstf = e(cdf); estadd scalar ovid = e(jp);
eststo: ivreg2hdfe if numberstudents_e>=3 & numberstudents_m>=3 ,  depvar(Y) ex($spec3) en(T1 T2) iv($instrument_avg $instrument3 $instrument4 $instrument5) id1(tidm) id2(tide) cluster(sch_id);
estadd scalar nst = round(e(N),10); estadd scalar firstf = e(cdf); estadd scalar ovid = e(jp);
esttab using $tables\EdEx_rep.tex, append cells(b(fmt(2) star) se(fmt(2) par))
collabels(none) 
nomtitles mgroups("Bartik" "Transitory" "Both", pattern(1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span) 
 starlevels(* 0.10 ** 0.05 *** 0.01) label keep(T1 T2) 
stats(r2 r2_a nst firstf ovid, fmt(2 2 0 2 2) labels(" $ R^2$ " "Adjusted $ R^2$ " "N" "1st StageF-test" "Over-identification test")) title(2SLS: The Effect of Teacher Expectation, with School FE);


